package com.store.practice.service.impl;

import com.store.practice.mapper.BgStoreMapper;
import com.store.practice.model.BgStore;
import com.store.practice.service.BgStoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BgStoreServiceImpl implements BgStoreService {
    @Autowired
    private BgStoreMapper storeMapper;


    private PasswordEncoder passwordEncoder(){
        return new BCryptPasswordEncoder();
    }

    @Override
    public int insert(BgStore store) {
        String pwEncode = passwordEncoder().encode(store.getPassword());
        store.setPassword(pwEncode);
        int i = storeMapper.insert(store);
        return i;
    }

    @Override
    public int update(BgStore store) {
        String pwEncode = passwordEncoder().encode(store.getPassword());
        store.setPassword(pwEncode);
        int i = storeMapper.updateByPrimaryKeySelective(store);
        return i;
    }

    @Override
    public List<BgStore> list() {
        return storeMapper.selectByExample(null);
    }
}
